﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using RN.ERP.BLL;
using Newtonsoft.Json;
using RN.ERP.DTO;
using System.ServiceModel.Activation;

namespace RN.ERP
{
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class KaoHeService : IKaoHeService
    {
        BaseKaoHeBll kaoheBll = (BaseKaoHeBll)BllFactory.CreateBll(BllType.KaoHe, Utilities.GetDbType());

        public string GetCorpDeDuckList(List<string> corpGuid, string areaCode)
        {
            return JsonConvert.SerializeObject(kaoheBll.GetCorpDeDuckList(corpGuid, areaCode));
        }

        #region 代理考核申请

        public string GetCorpSnapList(int pageCount, int pageSize, string conditions, int roleId)
        {
            return JsonConvert.SerializeObject(kaoheBll.GetCorpSnapList(pageCount, pageSize, conditions, roleId));
        }

        /// <summary>
        /// 返回申请信息
        /// </summary>
        /// <param name="keyGuid"></param>
        /// <param name="corpUserGuid"></param>
        /// <param name="appId"></param>
        /// <param name="areaCode"></param>
        /// <returns></returns>
        public string GetCorpSnap(
            string keyGuid,
            string snapType,
            string areaCode)
        {
            return JsonConvert.SerializeObject(kaoheBll.GetCorpSnap(
                keyGuid,
                snapType,
                areaCode));
        }

        /// <summary>
        /// 添加信用申请
        /// </summary>
        /// <param name="corpUserGuid"></param>
        /// <param name="appId"></param>
        /// <param name="areaCode"></param>
        /// <returns></returns>
        public string CorpSnapAdd(string corpUserGuid, string appId, string areaCode)
        {
            return JsonConvert.SerializeObject(kaoheBll.CorpSnapAdd(corpUserGuid, appId, areaCode));
        }

        /// <summary>
        /// 修改信用申请
        /// </summary>
        /// <param name="keyGuid"></param>
        /// <param name="appId"></param>
        /// <param name="areaCode"></param>
        /// <returns></returns>
        public string CorpSnapEdit(string keyGuid, string appId, string areaCode)
        {
            return JsonConvert.SerializeObject(kaoheBll.CorpSnapEdit(keyGuid, appId, areaCode));
        }

        /// <summary>
        /// 删除信用申请
        /// </summary>
        /// <param name="keyGuid"></param>
        /// <param name="areaCode"></param>
        /// <returns></returns>
        public string CorpSnapDel(string keyGuid, string areaCode)
        {
            return JsonConvert.SerializeObject(kaoheBll.CorpSnapDel(keyGuid, areaCode));
        }

        /// <summary>
        /// 申请上报
        /// </summary>
        /// <param name="keyGuid"></param>
        /// <param name="corpUserGuid"></param>
        /// <param name="areaCode"></param>
        /// <returns></returns>
        public string CorpSnapPost(string keyGuid, string corpUserGuid, string isrtUserGuid, string areaCode)
        {
            return JsonConvert.SerializeObject(kaoheBll.CorpSnapPost(keyGuid, corpUserGuid, isrtUserGuid, areaCode));
        }

        public string CorpCancel(
            string snapGuid,
            string isrtUserGuid,
            string areaCode,
            bool isAll,
            string content,
            string isrtUserRole)
        {
            return JsonConvert.SerializeObject(kaoheBll.CorpCancel(snapGuid, isrtUserGuid, areaCode, isAll, content, isrtUserRole));
        }

        /// <summary>
        /// 验证申请状态
        /// </summary>
        /// <param name="corpSnapGuid"></param>
        /// <returns></returns>
        public string CheckCorpSnapStatus(string corpSnapGuid, int flag, string areaCode)
        {
            return JsonConvert.SerializeObject(kaoheBll.CheckCorpSnapStatus(corpSnapGuid, flag));
        }

        /// <summary>
        /// 添加修改企业规章制度
        /// </summary>
        /// <param name="corpUserGuid"></param>
        /// <param name="regulatory"></param>
        /// <param name="areaCode"></param>
        /// <returns></returns>
        public string CompanyRegulatoryEdit(string corpUserGuid, string regulatory, string areaCode)
        {
            return JsonConvert.SerializeObject(kaoheBll.CompanyRegulatoryEdit(corpUserGuid, regulatory, areaCode));
        }

        /// <summary>
        /// 修改人员社保号
        /// </summary>
        /// <param name="empGuid"></param>
        /// <param name="corpUserGuid"></param>
        /// <param name="insuranceNum"></param>
        /// <param name="areaCode"></param>
        /// <returns></returns>
        public string PersonEmpInsuranceNumEdit(string empGuid, string corpUserGuid, string insuranceNum, string areaCode)
        {
            return JsonConvert.SerializeObject(kaoheBll.PersonEmpInsuranceNumEdit(empGuid, corpUserGuid, insuranceNum, areaCode));
        }

        /// <summary>
        /// 返回规章制度信息
        /// </summary>
        /// <param name="corpUserGuid"></param>
        /// <param name="areaCode"></param>
        /// <returns></returns>
        public string GetCompanyRegulatory(string corpUserGuid, string areaCode)
        {
            return kaoheBll.GetCompanyRegulatory(corpUserGuid, areaCode);
        }

        /// <summary>
        /// 修改企业开户行
        /// </summary>
        /// <param name="corpUserGuid"></param>
        /// <param name="regulatory"></param>
        /// <param name="areaCode"></param>
        /// <returns></returns>
        public string CompanyBankEdit(string corpUserGuid, string bankName, string bankAccNo, string areaCode)
        {
            return JsonConvert.SerializeObject(kaoheBll.CompanyBankEdit(corpUserGuid, bankName, bankAccNo, areaCode));
        }

        /// <summary>
        /// 判断企业本年度的申请信息是否存在
        /// </summary>
        /// <param name="corpSnapGuid"></param>
        /// <param name="corpUserGuid"></param>
        /// <param name="flag"></param>
        /// <returns></returns>
        public string CheckCorpSnapYearIsExist(string corpUserGuid, string areaCode)
        {
            return JsonConvert.SerializeObject(kaoheBll.CheckCorpSnapYearIsExist(corpUserGuid, areaCode));
        }

        #endregion

        #region 代理考核评分

        /// <summary>
        /// 主管信用评价实际初审意见汇总表
        /// </summary>
        /// <param name="evaluationId"></param>
        /// <param name="appId"></param>
        /// <param name="classId"></param>
        /// <param name="areaCode"></param>
        /// <returns></returns>
        public string GetCorpSnapEvaluationScoreSum(string startDate, string endDate, string corpRoleIds, string cityRoleIds, string appId, string areaCode)
        {
            return JsonConvert.SerializeObject(kaoheBll.GetCorpSnapEvaluationScoreSum(startDate, endDate, corpRoleIds, cityRoleIds, appId, areaCode));
        }

        /// <summary>
        /// 返回拥有查询证书的人员数
        /// </summary>
        /// <param name="corpUserGuid"></param>
        /// <param name="areaCode"></param>
        /// <returns></returns>
        public  int GetCorpPersonCert(string corpUserGuid, string areaCode, int typeFlags)
        {
            return kaoheBll.GetCorpPersonCert(corpUserGuid, areaCode, typeFlags);
        }

        /// <summary>
        /// 添加修改评分参数指标数据
        /// </summary>
        /// <param name="corpUserGuid"></param>
        /// <param name="regulatory"></param>
        /// <param name="areaCode"></param>
        /// <returns></returns>
        public string CorpEvaluationParamsEdit(string corpUserGuid, string evaluationParams, string areaCode)
        {
            return JsonConvert.SerializeObject(kaoheBll.CorpEvaluationParamsEdit(corpUserGuid, evaluationParams, areaCode));
        }

        /// <summary>
        /// 返回评分参数指标
        /// </summary>
        /// <param name="corpUserGuid"></param>
        /// <param name="areaCode"></param>
        /// <returns></returns>
        public string GetCorpAttachInfo(string corpUserGuid, string content, string areaCode)
        {
            return kaoheBll.GetCorpAttachInfo(corpUserGuid, content, areaCode);
        }

        /// <summary>
        /// 初审汇总表
        /// </summary>
        /// <param name="snapGuid"></param>
        /// <param name="corpRoleIds"></param>
        /// <param name="roleIds"></param>
        /// <param name="appId"></param>
        /// <param name="classId"></param>
        /// <param name="areaCode"></param>
        /// <returns></returns>
        public string CorpEvaluationItemsStatistic(string snapGuid, string corpRoleIds, string cityRoleIds, string appId, int classId, string areaCode)
        {
            return JsonConvert.SerializeObject(kaoheBll.CorpEvaluationItemsStatistic(snapGuid, corpRoleIds, cityRoleIds, appId, classId, areaCode));
        }

        /// <summary>
        /// 取得评分项列表
        /// </summary>
        /// <param name="appId"></param>
        /// <param name="classId"></param>
        /// <param name="areaCode"></param>
        /// <returns></returns>
        public string GetCorpEvaluationItems(int evaluationId, string appId, int classId, string areaCode)
        {
            return JsonConvert.SerializeObject(kaoheBll.GetCorpEvaluationItems(evaluationId, appId, classId, areaCode));
        }

        /// <summary>
        /// 取得当前用户的信用评价主表ID
        /// </summary>
        /// <param name="corpUserGuid"></param>
        /// <param name="snapGuid"></param>
        /// <param name="isrtUserGuid"></param>
        /// <param name="areaCode"></param>
        /// <returns></returns>
        public string GetCorpEvaluationScoreID(string corpUserGuid, string snapGuid, string isrtUserGuid, string areaCode)
        {
            return JsonConvert.SerializeObject(kaoheBll.GetCorpEvaluationScoreID(corpUserGuid, snapGuid, isrtUserGuid, areaCode));
        }

        /// <summary>
        /// 返回评分项及分值
        /// </summary>
        /// <param name="evaluationId"></param>
        /// <param name="appId"></param>
        /// <param name="classId"></param>
        /// <param name="areaCode"></param>
        /// <returns></returns>
        public string GetCorpEvaluationScore(int evaluationId, string appId, int classId, string areaCode)
        {
            return JsonConvert.SerializeObject(kaoheBll.GetCorpEvaluationScore(evaluationId, appId, classId, areaCode));
        }

        /// <summary>
        /// 返回评价上报状态
        /// </summary>
        /// <param name="corpEvalId"></param>
        /// <param name="areaCode"></param>
        /// <returns></returns>
        public string GetCorpEvaluationState(int corpEvalId, string areaCode)
        {
            return JsonConvert.SerializeObject(kaoheBll.GetCorpEvaluationState(corpEvalId, areaCode));
        }

        /// <summary>
        /// 根据角色查看企业评价表的各类打分信息
        /// 2014-5-16 毛凯
        /// </summary>
        /// <param name="snapGuid"></param>
        /// <param name="corpUserGuid"></param>
        /// <param name="areaCode"></param>
        /// <returns></returns>
        public string GetCorpEvaluationScoreList(
            string snapGuid,
            string corpUserGuid,
            string roleIds,
            string areaCode)
        {
            return JsonConvert.SerializeObject(kaoheBll.GetCorpEvaluationScoreList(snapGuid, corpUserGuid, roleIds, areaCode));
        }

        /// <summary>
        /// 打分汇总
        /// 2014-5-16 毛凯
        /// </summary>
        /// <param name="snapGuid"></param>
        /// <param name="corpUserGuid"></param>
        /// <param name="areaCode"></param>
        /// <returns></returns>
        public string SaveCorpEvaluation(
            string snapGuid,
            string corpUserGuid,
            string isrtUserGuid,
             string appId,
            int classId,
            string areaCode)
        {
            return JsonConvert.SerializeObject(kaoheBll.SaveCorpEvaluation(snapGuid, corpUserGuid, isrtUserGuid, appId, classId, areaCode));
        }
        #endregion

        #region 企业评价信息子表
        public string AddCorpEvaluationSub(string corpEvaSub)
        {
            return JsonConvert.SerializeObject(kaoheBll.AddCorpEvaluationSub(corpEvaSub));
        }

        public string GetCorp_EvaluationSub(int itemID, int treeID)
        {
            return kaoheBll.GetCorp_EvaluationSub(itemID, treeID);
        }
        #endregion

        #region 聊城年检
        public string GetEntitySnapList(
        int pageNum,
        int pageSize,
        string conditions,
        out int cnt)
        {
            return JsonConvert.SerializeObject(kaoheBll.GetEntitySnapList(pageNum, pageSize, conditions, out cnt));
        }

        public string GetEntitySnapInfo(string entityGuid, int snapKind)
        {
            return JsonConvert.SerializeObject(kaoheBll.GetEntitySnapInfo(entityGuid, snapKind));
        }

        public string SaveEntitySnapInfo(string snapModel)
        {
            var model = JsonConvert.DeserializeObject<DTO.EntitySnap>(snapModel);
            return JsonConvert.SerializeObject(kaoheBll.SaveEntitySnapInfo(model));
        }

        public string DeleteSnapInfo(string keyGuid, string areaCode)
        {
            return JsonConvert.SerializeObject(kaoheBll.DeleteSnapInfo(keyGuid, areaCode));
        }

        public string SaveAssessmentDetails(string data,string areaCode)
        {         
            var model = JsonConvert.DeserializeObject<DTO.tb_AssessmentDetailsModel>(data);
            return JsonConvert.SerializeObject(kaoheBll.SaveAssessmentDetails(model));
           
        }

        public string  DeleteAssessmentDetails(int id, string optUser, string areaCode)
        {
            return JsonConvert.SerializeObject(kaoheBll.DeleteAssessmentDetails(id,optUser,areaCode));
        }

        /// <summary>
        /// 查询企业考核指标详细信息,指定指标请使用condition中IndexIDList
        /// </summary>
        /// <param name="corpUserGuid"></param>
        /// <param name="condition"></param>
        /// <param name="areaCode"></param>
        /// <returns></returns>
        public string GetCorpAssessmentDetails(string corpUserGuid,string  condition, string areaCode)
        {            
            var query = JsonConvert.DeserializeObject<DTO.tb_dict_PerformanceAssessmentIndexModel>(condition);
            return JsonConvert.SerializeObject(kaoheBll.GetCorpAssessmentDetails(corpUserGuid, query, areaCode));          
        }
        #endregion
    }
}
